var primePools = [];
var primes = [];

function getPrimes(limit) {
    var sqrt = Math.floor(Math.sqrt(limit));
    primePools[2] = 0;
    for(var i=2; i<=sqrt; i++) {
        for(var j=i*2; j<=limit; j=j+i) {
            primePools[j] = 1;
        }
    }
}

function isPrime(num) {
    return primePools[num] != 1
}

print('get primes.....');
var t=new Date().getTime();
var plimit = 100000
getPrimes(plimit);
for(var i=2; i<=plimit; i++) {
    if(isPrime(i)) primes.push(i);
}
print('get primes done..... ' + ((new Date().getTime()-t)/1000) + "s");

var checkNum = function(num) {
    for(var i=1; i<primes.length; i++) {
        if(primes[i]>num) return false;
        var tmp = (num-primes[i])/2;
        if(Math.sqrt(tmp)%1==0) return num + "="+ primes[i] + "+ 2*" + Math.sqrt(tmp) + "^2";
    }
}

for(var i=9; i<plimit; i=i+2) {
    if(isPrime(i)) continue;
    var tmp = checkNum(i);
    if(tmp) {
        print(tmp)
    } else {
        print("find...." + i);
        break;
    }

}
